package day12.reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Scanner;

public class Test1 {
    public static void main(String[] args) throws ClassNotFoundException {
        /*
        java.lang.String
        java.util.Date
        java.util.ArrayList
        java.io.File
        java.io.FileInputStream
         */
        System.out.print("输入类名:");
        String s = new Scanner(System.in).nextLine();
        Class<?> c = Class.forName(s);
        System.out.println(c.getPackage().getName());
        System.out.println(c.getName());
        System.out.println(c.getSimpleName());

        System.out.println("------成员变量--------");
        f1(c);
        System.out.println("------构造方法--------");
        f2(c);
        System.out.println("------方法--------");
        f3(c);



    }

    private static void f1(Class<?> c) {
        Field[] fields = c.getDeclaredFields();
        /*
        public static final Date date
         */
        for (Field f: fields) {
            String m = Modifier.toString(f.getModifiers());
            String t = f.getType().getSimpleName();
            String name = f.getName();
            System.out.println(m+" "+t+" "+name);
        }

    }

    private static void f2(Class<?> c) {
        Constructor<?>[] constructors = c.getDeclaredConstructors();
        for (Constructor<?> t: constructors) {
            String m = Modifier.toString(t.getModifiers());
            //构造方法名
            String n = c.getSimpleName();
            //参数类型列表
            Class<?>[] p = t.getParameterTypes();
            System.out.println(m+" "+n+" "+"("+ Arrays.toString(p)+")");
        }
    }

    private static void f3(Class<?> c) {
        Method[] methods = c.getDeclaredMethods();
        for (Method t: methods) {
            String m = Modifier.toString(t.getModifiers());
            //返回类型
            String simpleName = t.getReturnType().getSimpleName();
            Class<?>[] p = t.getParameterTypes();
            System.out.println(m+" "+simpleName+" "+p+"("+ Arrays.toString(p)+")");
        }
    }
}
